package com.hongyan.main;


import com.hongyan.base.BaseJpanel;
import com.hongyan.config.MainFrameConfig;
import com.hongyan.util.SnowflakeUtils;
import com.hongyan.view.SwingLoginPanel;
import com.lijinjiang.beautyeye.BeautyEyeLNFHelper;

import javax.swing.*;
import java.awt.*;

public class SwingMainFrame extends JFrame {
    public JPanel getContentPanel() {
        return contentPanel;
    }

    private JPanel contentPanel;

    public SwingMainFrame() throws HeadlessException {

        try {
            /**
             * 设置本属性将改变窗口边框样式定义
             * 系统默认样式 : osLookAndFeelDecorated
             * 强立体半透明 : translucencyAppleLike
             * 弱立体半透明 : translucencySmallShadow
             * 普通不透明 : generalNoTranslucencyShadow
             */
            BeautyEyeLNFHelper.frameBorderStyle = BeautyEyeLNFHelper.FrameBorderStyle.osLookAndFeelDecorated;
            BeautyEyeLNFHelper.launchBeautyEyeLNF();
        } catch (Exception e) {
            e.printStackTrace();
        }

        setTitle("软件测试管理系统");
        setSize(800, 600);
        setLocationRelativeTo(null);

        contentPanel = new JPanel();
        setContentPane(contentPanel);
        contentPanel.setLayout(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setResizable(false);
        setVisible(true);
    }

    public static void main(String[] args) {
        MainFrameConfig.setSnowflakeUtils(new SnowflakeUtils(1, 1));
        SwingUtilities.invokeLater(() -> {
            SwingMainFrame swingMainFrame = new SwingMainFrame();
            MainFrameConfig.setSwingMainFrame(swingMainFrame);
            SwingLoginPanel swingLoginPanel = new SwingLoginPanel(swingMainFrame);
            swingMainFrame.replacePanel(swingLoginPanel);
        });

    }

    public void replacePanel(BaseJpanel panel) {
        contentPanel.removeAll();
        // 添加新的组件
        setSize(panel.getJpanelWidth(), panel.getJpanelHeight());
        setTitle(panel.title());
        contentPanel.add(panel);
        // 更新界面
        contentPanel.revalidate();
        contentPanel.repaint();

    }
}

